<?php
include_once "xAP-functions/webincludes.php";

$id=intval($_GET["id"]);

if($_GET["cat"]!=""){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID
			where a.Category='".dbesc($_GET["cat"])."' 
			
			order by s.datestamp DESC limit 20";
}elseif($_GET["tag"]!=""){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID INNER JOIN xAP_News_Story_Tag as tg ON
			tg.StoryID=s.StoryID
			where tg.Tag='".dbesc($_GET["tag"])."' 
			
			order by s.datestamp DESC limit 20";
}elseif($id==0){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID order by s.datestamp DESC limit 20";
}else{
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID 
			where s.SourceID=".$id."
			order by s.datestamp DESC limit 20";
}

$results=dbquery($sql);

foreach($results as $v){
	$tag=explode(",",$v["TagList"]);
	/*
	if (strpos($v["Body"],">")==0){
		foreach($tag as $t){
			$v["Body"]=str_ireplace($t, "<a href='#' OnClick=\"Tag('".$t."');\">".$t."</a>",$v["Body"]);
		}
	}
	*/
	echo "
	<div class='block'>
	<div class='blocktitle'>
	<div class='topright'><a href='#' OnClick=\"NewsLoad(".$v["SourceID"].");\">".$v["Alias"]."</a></div>
	<a href=\"".$v["URL"]."\">".$v["Title"]."</a>, <span class='date'>".date($config["fulldateformat"],strtotime($v["DateStamp"]))."</span></div>
	<div class='blockbody'>".$v["Body"]."</div>
	<div class='blockbody normalsmalltext'>";
	
	foreach($tag as $t){
		echo "<a href='#' OnClick=\"Tag('".$t."');\">".$t."</a> ";
	}
	
	echo "</div>
	</div>
	";

}
?>